% parameters to be specified:
path = "D:\Sea1_local_np4_raw\*_z*_t*.dat";
shape2D = [51, 1051];
is_raw = true;



% begin the postprocessing process:
file = dir(path);
n = length(file);

for i = 1 : n
    file_name = file(i).name;
    % todo: exclude the 3D data contained in the same folder
    file_folder = file(i).folder;
    fp = fopen(strcat(file_folder, '/', file_name), "rb");

    if is_raw
        [wave2D, num] = fread(fp, shape2D, "double");
    else
        [wave2D, num] = fread(fp, shape2D, "short");
    end
    
    wave2D = abs(wave2D);
    % figure = imshow(uint8(wave2D / max(wave2D) * 255));

    fclose(fp);

    new_file_name = strrep(file_name, ".dat", ".png"); % todo: special naming could lead to inconsistent file names
    new_file_name = strcat(file_folder, '\', new_file_name);

    max_val = max(max(wave2D));
    temp_wave2D = uint8(wave2D / max_val * 255);
    imwrite(temp_wave2D, new_file_name);
end

